The name of the file and the name of the class must coincide
exactly. For example the Queue
class should be
in a file named Queue.java
.
Note that Java is case-sensitive (even though some versions of
MS-Windows are not).
This is so that automated testing tools have a place to insert comments/remarks if necessary.
The only exception to this rule is that all constructors must
be listed first. For example, in a Queue
class, the
constructor(s) should be first, the pop
method should
be second, and the push
method should be third.
Within each category, public variables must be declared first, followed by protected variables, followed by package variables, followed by private variables.
For example, variables of type double
should be declared
before variables of type int
which should, in turn,
be declared before variables of type Node
.
In addition, each "word" within a class name should start
with an uppercase letter.
For example, TextMessage
and
SimpleTrafficMonitor
are both appropriate class names.
Further, "words" within a "constant" name must be delimited by
an underscore character.
For example, EXTREMELY_UNHEALTHY
is an
appropriate name for a "constant".
Further, each "word" within a variable name should start
with an uppercase letter.
For example, importantMessage
and
campusMonitor
are both appropriate variable names.
In general, even single-character variable names should be lowercase.
However, in some situations, mathematical notation uses uppercase
letters. In such situations, uppercase variable names may be used.
For example, matrices are often written using uppercase letters.
So, an expression like b = A*x
would be appropriate.
Variable names like aaa
are not appropriate.
Index variables and counters can, however, have names like
i
and j
.
Do not rely on default visibilities.
Indeed, they must have private or protected visibility unless there is a very good reason for them to have public or package visibility.
@Override
annotation.
Indeed, they must be final unless there is a very good reason for them not to be.
They must begin with the visibility, followed by the
abstract
modifier if needed, followed by
the static
modifier if needed, followed by
the final
modifier if needed, followed by the
type.
This comment should describe the complete class (rather than the methods in the class).
This comment should describe the methods, its parameters, and its return value.
javadoc
is a program (written in Java) that creates external documentation
(in HTML) from block comments. All of the Java documentation was,
in fact, created this way. javadoc block comments start with
/**
and end with */
.
//
rather than /* ... */
.
This isn't a requirement but it will make your life easier since you can't nest block comments. There is nothing more annoying then trying to "comment out" a section of code while you are debugging and being unable to do so because it contains block comments.
* * This work complies with the JMU Honor Code. *
@author
element.
switch
statements.
switch
statements must have a
default
clause.
default
clause must be after
all case
clauses in a switch
statement.
case
clauses in switch
statements
must not fall-through
return
statements within a single
method should be avoided.
Early return
statements for error-checking are encouraged,
but other uses of multiple return
statements are
discouraged. Complicated Boolean return statements must be avoided.
More than 4 return statements is prohibited.
Parameters in constructors and setters may.
Such literals are often referred to as "magic numbers". (Note: -1, 0, 1, and 2 are generally not considered "magic numbers".)
equals()
method
must override equals(java.lang.Object)
.
equals(java.lang.Object
must override hashCode()
.
==
or
!=
oeprators.
java.lang.Exception
, java.lang.Error
,
and java.lang.RuntimeException
must never
be caught.
String
literal must not be used
multiple times in the same class.
clone()
method must call
super.clone()
.
finalize()
method must call
super.finalize()
.
Copyright 2023